/* 
 *  <copyright file="ContentProcessor1.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using SobrietyEngine.Common;
using SobrietyEngine.Assets.Textures;

// TODO: replace these with the processor input and output types.

namespace SobrietyCP
{

        [ContentTypeWriter]
        public class LevelContentWriter : ContentTypeWriter<Parameters>
        {
            protected override void Write(
            ContentWriter output,
            Parameters value)
            {
                //System.Diagnostics.Debugger.Launch();
                output.WriteObject<Dictionary<String, Object>>(value.Params);
            }

            public override string GetRuntimeReader(
            TargetPlatform targetPlatform)
            {
                //return typeof(SobrietyEngine.Common.ParametersContentReader).AssemblyQualifiedName;
                return "SobrietyEngine.Common.ParametersContentReader, SobrietyEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
            }

        } // Class XMLLevelWriter

        [ContentTypeWriter]
        public class AnimationDataContentWriter : ContentTypeWriter<AnimationData>
        {
            protected override void Write(
            ContentWriter output,
            AnimationData value)
            {
                //System.Diagnostics.Debugger.Launch();
                output.WriteObject<String>(value.AnimationSetName);
                foreach (List<FrameData> l in value.Animations.Values)
                {
                    if (l.Count > 0)
                    {
                        if (l[0].TextureName.Contains("#"))
                        {
                            int numFrames = Int16.Parse(l[0].TextureName.Split('#')[1]);
                            String texName = l[0].TextureName.Split('#')[0];
                            float time = l[0].Time;
                            l.Clear();
                            String leadingZeros = "00";
                            for (int frame = 0; frame < numFrames; frame++)
                            {
                                l.Add(new FrameData(texName+leadingZeros+frame,time));
                                if (frame == 9)
                                    leadingZeros = "0";

                            }
                        }
                    }
                }
                output.WriteObject<Dictionary<String, List<FrameData>>>(value.Animations);
            }

            public override string GetRuntimeReader(
            TargetPlatform targetPlatform)
            {
                return "SobrietyEngine.Assets.Textures.AnimationDataContentReader, SobrietyEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
            }

        }

        [ContentTypeWriter]
        public class FrameDataContentWriter : ContentTypeWriter<FrameData>
        {
            protected override void Write(
            ContentWriter output,
            FrameData value)
            {
                //System.Diagnostics.Debugger.Launch();
                output.WriteObject<String>(value.TextureName);
                output.WriteObject<float>(value.Time);
            }

            public override string GetRuntimeReader(
            TargetPlatform targetPlatform)
            {
                return "SobrietyEngine.Assets.Textures.FrameDataContentReader, SobrietyEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
            }

        }

}